package controller

import (
	"fmt"
	"study/dao"
	"study/log"
	"study/model"
	"study/spider"

	"github.com/gin-gonic/gin"
)

func Hello(context *gin.Context) {

	db := dao.Db

	// Create
	db.Create(&model.AppUser{Name: "张捷", Sex: 2})

	// Read
	var appuser model.AppUser
	// db.First(&appuser, 1) // find product with integer primary key
	db.First(&appuser, "name = ?", "张捷") // find product with code D42
	var appusers []model.AppUser
	result := db.Where(&model.AppUser{Name: "张捷"}).Find(&appusers)

	fmt.Println("=============", result.RowsAffected)
	fmt.Println("=============", appusers)
	fmt.Println("=============", appuser.ID)

	context.JSON(200, gin.H{
		"code":    200,
		"success": true,
		"data":    appuser,
	})

}
func Spider(context *gin.Context) {
	log.Logger.Info("==================开始爬虫====================")
	// spider.PoetrySpider.Execute()
	spider.SouGouHaHaSpider()
	context.JSON(200, gin.H{
		"code":    200,
		"success": true,
	})
}
